package com.hmall.trade.listener;

import com.hmall.trade.service.IOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class PayStatusListener {

    private final IOrderService orderService ;

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(value = "trade.pay.success.queue",durable = "true"),
                    exchange = @Exchange("pay.direct"),
                    key = {"pay.success"}
            )
    )
    public void listenerPaySuccess(Long orderId) {
        // orderId 就是你这个消息传送的内容 相当于通过内容传参
        orderService.markOrderPaySuccess(orderId);
    }
}
